package com.ymatou.iapi.dguser.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.GetUserListByNameBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetUserListByNameCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据昵称获查询用户信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserListByName{
	private static GetUserListByNameBean getuserlistbynameBean;
	private static GetUserListByNameCall getuserlistbynameCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据昵称获查询用户信息");
	}

	@Before
	public void caseUp() {
		getuserlistbynameBean=new GetUserListByNameBean();
		getuserlistbynameCall=new GetUserListByNameCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserlistbynameCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserListByName_001() {
		Logger.start(true,"根据昵称获查询用户信息");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setNickname(TestDataManager.getPhoneNum());
			Integer user = DGUserCallService.UserCreateCall(u);
			getuserlistbynameBean.setNickname(u.getNickname());
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("true", getuserlistbynameCall.getString("success"), "验证success");
			List<Integer> userlist=new ArrayList<Integer>();
			getuserlistbynameCall.getJsonObject().get("userDtos").getAsJsonArray().forEach(json->{
				Integer uid=json.getAsJsonObject().get("userId").getAsInt();
				userlist.add(uid);
			});
			Logger.verifyEquals(true, userlist.contains(user), "验证uid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserListByName_002() {
		Logger.start(true,"输入不存在昵称失败");
		try {
			getuserlistbynameBean.setNickname("-1");
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("true", getuserlistbynameCall.getString("success"), "验证success");
			Logger.verifyEquals(0, getuserlistbynameCall.getJsonObject().get("userDtos").getAsJsonArray().size(), "验证没有数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetUserListByName_003() {
		Logger.start(true,"不输入昵称失败");
		try {
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("false", getuserlistbynameCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserListByName_004() {
		Logger.start(true,"根据昵称获查询用户信息-昵称存在多个全部查出");
		try {
			String nick=TestDataManager.getPhoneNum();;
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setNickname(nick);
			Integer user = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initUsercreateBean();
			u2.setNickname(nick);
			Integer user2 = DGUserCallService.UserCreateCall(u2);
			
			getuserlistbynameBean.setNickname(nick);
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("true", getuserlistbynameCall.getString("success"), "验证success");
			List<Integer> userlist=new ArrayList<Integer>();
			getuserlistbynameCall.getJsonObject().get("userDtos").getAsJsonArray().forEach(json->{
				Integer uid=json.getAsJsonObject().get("userId").getAsInt();
				userlist.add(uid);
			});
			Logger.verifyEquals(true, userlist.contains(user), "验证uid");
			Logger.verifyEquals(true, userlist.contains(user2), "验证uid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserListByName_005() {
		Logger.start(true,"根据昵称获查询用户信息-nickname包含emoji表情");
		try {
			String name = "nick😑😊😳"+TestDataManager.getChineseName();
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setNickname(name);
			Integer user = DGUserCallService.UserCreateCall(u);
			getuserlistbynameBean.setNickname(u.getNickname());
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("true", getuserlistbynameCall.getString("success"), "验证success");
			List<Integer> userlist=new ArrayList<Integer>();
			getuserlistbynameCall.getJsonObject().get("userDtos").getAsJsonArray().forEach(json->{
				Integer uid=json.getAsJsonObject().get("userId").getAsInt();
				userlist.add(uid);
			});
			Logger.verifyEquals(true, userlist.contains(user), "验证uid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserListByName_006() {
		Logger.start(true,"根据昵称获查询用户信息-支持模糊查询");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			String u1=TestDataManager.getPhoneNum();
			u.setNickname("search"+u1+"mh");
			Integer user = DGUserCallService.UserCreateCall(u);
			getuserlistbynameBean.setFuzzyMatch(true);
			getuserlistbynameBean.setNickname(u1);
			getuserlistbynameCall.setData(getuserlistbynameBean);
			getuserlistbynameCall.callService();			
			Logger.verifyEquals("true", getuserlistbynameCall.getString("success"), "验证success");
			List<Integer> userlist=new ArrayList<Integer>();
			getuserlistbynameCall.getJsonObject().get("userDtos").getAsJsonArray().forEach(json->{
				Integer uid=json.getAsJsonObject().get("userId").getAsInt();
				userlist.add(uid);
			});
			Logger.verifyEquals(true, userlist.contains(user), "验证uid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}